package com.situ.blog.service.impl;



import com.situ.blog.dao.IAdminDao;
import com.situ.blog.dao.impl.AdminDaoImpl;
import com.situ.blog.pojo.Admin;
import com.situ.blog.pojo.query.AdminQuery;
import com.situ.blog.service.IAdminService;
import com.situ.blog.util.PageResult;

import java.util.List;

public class AdminServiceImpl implements IAdminService {
    private IAdminDao adminDao = new AdminDaoImpl();

    @Override
    public PageResult selectByPage(AdminQuery adminQuery) {
        List<Admin> list = adminDao.selectByPage(adminQuery);
        int totalCount = adminDao.selectTotalCount(adminQuery);

        PageResult<Admin> pageResult = new PageResult<>(0, "", totalCount, list);
        return pageResult;
    }

    @Override
    public void deleteById(int id) {
        adminDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        //delete from admin where id in(2,3)
        for (String id : ids) {
            adminDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Admin admin) {
        adminDao.add(admin);
    }

    @Override
    public Admin selectById(int id) {
        return adminDao.selectById(id);
    }

    @Override
    public void update(Admin admin) {
        adminDao.update(admin);
    }

    @Override
    public void updateStatus(String id, int status) {
        adminDao.updateStatus(id, status);
    }

    @Override
    public Admin login(String name, String password) {
        return adminDao.login(name, password);
    }
}
